<template>
  <div class="index-container">
    <div class="shop-top">
      <div class="w1200">
        <div class="fr" ><router-link :to="`/shoplist`" title="融易装">
              <i class="el-icon-house" style="margin-right:5px;"></i>首页
            </router-link></div>
        <div class="fl">
          <div class="sn-quick-menu">
            <div class="login"><img v-if="info.logo"
                   :src="info.logo.path"
                   alt="">{{info.name?info.name:'暂未设置'}}
              <i class="el-icon-arrow-down el-icon--right"></i>
            </div>
            <!-- <div class="sp-cart">客服服务
              <i class="el-icon-arrow-down"></i>
            </div> -->
          </div>
        </div>
      </div>
    </div>

    <div class="header">
      <div class="headerLayout w1200">
        <div class="headerCon">
          <h1 class="mallLogo">
            <router-link :to="`/shoplist`"
                         title="融易装">
              <img src="../img/logo.png">
            </router-link>
          </h1>
          <div class="mallSearch">
            <form action=""
                  class="layui-form"
                  novalidate>
              <input type="text"
                     v-model="keyword"
                     class="layui-input"
                     placeholder="搜索关键字">
              <button class="layui-btn"
                      @click="filterPops()">
                <i class="el-icon-search"></i>
              </button>
            </form>
          </div>
        </div>
      </div>
    </div>

    <div class="content content-nav-base commodity-content">

      <div class="main-nav">
        <div class="inner-cont0">
          <div class="inner-cont1 w1200">
            <div class="category-types"
                 style="">
              <h3>全部分类</h3>
            </div>
            <div class="inner-cont2">
              <router-link :to="`/nowlist`">选材中心</router-link>
              <router-link :to="`/orderlist`">我的订单</router-link>
              <router-link :to="`/nowadderss`">地址管理</router-link>
              <router-link :to="`/nowcart`">购物车</router-link>
            </div>
          </div>
        </div>
      </div>

      <div class="commod-cont-wrap"
           style="background:#f8f8f8;">
        <div class="commod-cont w1200 layui-clear">
          <div class="order-top">确认订单</div>
          <div class="orderdeatil">
            <h2>填写并核对订单信息</h2>
            <h4>收货人信息 <span @click="gitadderss()"><i class="el-icon-plus"></i>新增地址</span></h4>
            <div class="consignee-scroll">
              <ul class="consignee-cont" :class="{active:addshowlist==true}" v-if="addressDatas.list.length>0">
                <li class="ui-switchable-panel ui-switchable-panel-selected" style="display: list-item;">
                  <div class="consignee-item item-selected">
                    <span>{{curAddress.name}}</span>
                  </div>
                  <div class="addr-detail">
                    <span class="addr-name">{{curAddress.name}}</span>
                    <span class="addr-info">{{curAddress.province}} {{curAddress.city}} {{curAddress.area}} {{curAddress.address}}</span>
                    <span class="addr-tel">{{curAddress.mobile}}</span>
                    <span class="addr-default" v-if="curAddress.is_default == 1">默认地址</span>
                  </div>
                  <div class="op-btns" consigneeid="643171686" isoldaddress="false" @click="editAddress(curAddress)">
                    <span></span><span class="ftx-05 edit-consignee">编辑</span>
                  </div>
                </li>
                <li class="ui-switchable-panel" v-for="(item,index) in addressDatas.list" :key="index" style="display: list-item;" v-if="curAddress.id != item.id">
                  <div class="consignee-item" @click="gitchoseadd(item.id)">
                    <span>{{item.name}}</span>
                  </div>
                  <div class="addr-detail">
                    <span class="addr-name">{{item.name}}</span>
                    <span class="addr-info">{{item.province}} {{item.city}} {{item.area}} {{item.address}}</span>
                    <span class="addr-tel">{{item.mobile}}</span>
                    <span class="addr-default" v-if="item.is_default == 1">默认地址</span>
                  </div>
                  <div class="op-btns" consigneeid="643171686" isoldaddress="false" @click="editAddress(item)">
                     <span></span><span class="ftx-05 edit-consignee">编辑</span>
                  </div>
                </li>
              </ul>
              <div class="noadderss" v-else>暂无收货地址，请先添加收货地址！</div>
            </div>
            <div class="addr-switch switch-on" @click="gitaddshowlist()" v-if="addressDatas.list.length>0">
                <span>更多地址 <i v-if="!addshowlist" class="el-icon-arrow-down"></i><i v-else class="el-icon-arrow-up"></i></span>
            </div>
            <div class="addr-switch switch-on" @click="gitadderss()" v-else>
                <span><i class="el-icon-plus"></i>新增地址 </span>
            </div>
            <h4>清单信息</h4>
            <div class="goods-list" v-for="(items,indexs) in skuList" :key="indexs">     
              <div class="goods-tit">
                  <h4 class="vendor_name_h vendor_name_0"><i class="el-icon-s-shop"></i>{{items.store_name}}</h4>
              </div>
              <div class="goods-items" v-for="(item,index) in items.goods" :key="index">
                  <div class="goods-suit goods-last">
                    <div data-service=""></div>
                      <div class="goods-item goods-item-extra">
                  <div class="p-img">
                    <router-link :to="{path:'/shopdeatil',query: {product_id: item.product_id}}"><img :src="item.main_imgurl" alt=""></router-link> 
                  </div>
                  <div class="goods-msg">
                      <div class="goods-msg-gel">			
                        <div class="p-name">
                            {{item.product_title}}
                         </div>
                        <div class="p-price ">
                          <strong class="jd-price">底价 ￥ {{item.cost_price}}<em class=""></em></strong>
                          <span class="p-num"> 售价 ￥{{item.price}}</span> 
                          <span class="p-num"> 原价 ￥{{item.primary_price}}</span> 
                        </div>
                      </div>    
                  </div>
                  <div class="c_cpay_nums">
                    <div class="c_cnMinus el-icon-minus" @click="minusCart(items.store_id, item)"></div>
                    <div class="c_cnpay_num">{{item.pay_num}}</div>
                    <div class="c_cnAdd el-icon-plus" @click="addCart(items.store_id, item)"></div>
                  </div>
                          <div class="p-extra-continer">
                            <div class="p-extra-line">
                                  <div class="fr" v-for="(item2,index2) in item.attribute" :key="index2"><span>{{item2.value}}</span></div>
                            </div>
                          </div> 
                      </div>
                  </div>
              </div>
          </div>
          <h4>支付方式</h4>
          <div class="paybox">
            <div class="left-box" @click="radioChange(1)" :class="{active:tapIndex==1}"><div class="weixin"></div>微信支付</div>
            <div class="left-box" @click="radioChange(2)" :class="{active:tapIndex==2}"><div class="xianxia"></div>线下支付</div>
          </div>
          <!-- 价格 -->
          <div class="order-summary">
            <div class="statistic">
                <div class="list">
                          <span>总商品金额：</span>
                          <em class="price">￥{{infos.order_price}}</em>
                </div>
                <div class="list">
                        <span>运费：</span>
                        <em class="price"><font color="#000000"> ￥0.00</font></em>
                </div>

            </div>
          </div>
          <!-- 总额 -->
          <div class="trade-foot">
             <div class="trade-foot-detail-com">
               <div class="fc-price-info" v-if="infos.order_is_many_way == 1">
                        <span class="price-tit">应付定金：</span>
                        <span class="price-num" id="sumPayPriceId" v-if="infos.order_deposit_money">￥{{infos.order_deposit_money || '0.00'}}</span>
                </div>
                <div class="fc-price-info">
                        <span class="price-tit">应付总额：</span>
                        <span class="price-num" id="sumPayPriceId">￥{{infos.order_price || '0.00'}}</span>
                </div>
                <div class="fc-consignee-info" v-if="curAddress">
                    <span class="mr20" id="sendAddr">寄送至：{{curAddress.province}} {{curAddress.city}} {{curAddress.area}} {{curAddress.address}}</span>
                    <span id="sendMobile">收货人：{{curAddress.name}} {{curAddress.mobile}}</span>
                </div>
             </div>
          </div>
          <!-- 提交 -->
          <div class="checkout-buttons">
             <el-button class="checkout-submit" type="danger" :disabled="disabled" @click="submitEvent()">提交订单</el-button>
          </div>

          </div>
          
        </div>
      </div>
    </div>
    <el-dialog
      title="订单支付"
      :visible.sync="dialogVisible"
      width="35%"
      :before-close="handleClose">
      <div class="ep-order">
         <div class="ep-order-tit"> <dl><dt>商品订单：</dt> <dd>{{order_codes}}</dd> </dl> </div>
         <div class="ep-order-tit"> <span v-if="infos.order_is_many_way == 1">支付金额：<em class="rmb"><i>¥</i>{{infos.order_deposit_money || '0.00'}}</em></span><span v-else>支付金额：<em class="rmb"><i>¥</i>{{infos.order_onepay_money || '0.00'}}</em></span></div>
          <div class="ep-pay-method">
              <dl> 
                <dt v-if="tapIndex == 1">支付方式：微信支付</dt>
                <dt v-else>支付方式：线下支付</dt>
                <dd class="pay-channel ">
                  <div v-if="tapIndex == 1"><img style="width:200px;height:200px" :src="code_url" /></div>
                  <qriously v-else :value="initQCode" :size="200"/>  
                  <div v-if="tapIndex == 1" class="ep-wxpay-qrcode-notice">请打开手机微信，扫一扫完成支付</div>
                  <div v-else class="ep-wxpay-qrcode-notice">请扫一扫进行核销</div>    
                </dd>
              </dl>
          </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <!-- <el-button @click="dialogVisible = false">取 消</el-button> -->
        <el-button type="primary" @click="gitdialog()">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      :title="addtit"
      :visible.sync="dialogadders"
      width="900px"
      :before-close="handleClose">
      <div class="addersscont">
        <el-form ref="form" :model="form" label-position="left">
          <el-form-item label="收货姓名" label-width="80px">
              <el-input style="width:100%;" v-model="form.name" placeholder="请输入收货人姓名"></el-input>
            </el-form-item> 
            <el-form-item label="手机号码" label-width="80px">
              <el-input style="width:100%;" v-model="form.mobile" placeholder="请输入收货人手机号"></el-input>
            </el-form-item> 
           <el-form-item label="选择区域" label-width="80px">
              <el-select v-model="provinceObj" @change="select1" value-key="cityid" placeholder="请选择省份">
                <el-option
                v-for="item in province"
                :key="item.cityid"
                :label="item.city_name"
                :value="{cityid:item.cityid,city_name:item.city_name}">
                </el-option>
              </el-select>
              <el-select v-model="cityObj" @change="select2" value-key="cityid" placeholder="请选择城市">
                <el-option
                v-for="item in city"
                :key="item.cityid"
                :label="item.city_name"
                :value="{cityid:item.cityid,city_name:item.city_name}">
                </el-option>
              </el-select>
              <el-select v-model="districtObj" @change="select3" value-key="cityid" placeholder="请选择县区">
                <el-option
                v-for="item in district"
                :key="item.cityid"
                :label="item.city_name"
                :value="{cityid:item.cityid,city_name:item.city_name}">
                </el-option>
              </el-select>
            </el-form-item> 
            <el-form-item label="详细地址" label-width="80px">
              <el-input style="width:100%;" v-model="form.address" placeholder="请输入详细地址"></el-input>
            </el-form-item>
            <el-form-item label="设为默认" label-width="80px">
              <el-radio v-model="form.is_default" label="1">是</el-radio>
            </el-form-item>    
        </el-form>       
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogadders = false">取 消</el-button>
        <el-button type="primary" v-if="address_id" @click="getedit()">保存修改</el-button>
        <el-button type="primary" v-else @click="getadd()">确 定</el-button>
        
      </span>
    </el-dialog>
    

    <div class="footer">
      <div class="ng-promise-box">
        <div class="ng-promise w1200">
          <p class="text">
            <a class="icon1"
               href="javascript:;">7天无理由退换货</a>
            <a class="icon2"
               href="javascript:;">送货上门</a>
            <a class="icon3"
               style="margin-right: 0"
               href="javascript:;">100%品质保证</a>
          </p>
        </div>
      </div>
      <div class="mod_help w1200">
        <!-- <p>
        <a href="javascript:;">关于我们</a>
        <span>|</span>
        <a href="javascript:;">帮助中心</a>
        <span>|</span>
        <a href="javascript:;">售后服务</a>
        <span>|</span>
        <a href="javascript:;">行业资讯</a>
        <span>|</span>
        <a href="javascript:;">关于货源</a>
      </p> -->
        <p class="coty">融易装版权所有 &copy; 2012-2020</p>
      </div>
    </div>

  </div>
</template>

<script>
  import QRCode from 'qrcodejs2'
  export default {
    data() {
      return {
        name: '小刀',
        info: {},
        paramsdata:{},
        skuList:[],
				infos:"",
        totalPrice:'',
				Nocart :'',
				origin_type:'',
        form: {
           name:"",
           mobile:'',
           address:'',
           is_default:0,
        },
        province:[],
        city:[],
        district:[],
        provinceObj:{},
        cityObj:{},
        districtObj:{},
        mobile: '',
        activeName: '1',
        keyword: '',
        dialogVisible: false,
        dialogadders:false,
        addressDatas:{
					loading:false,
					fail:false,
					list:[],
					index:0
				},
        tapIndex:1,
        addtit:'新增收货地址',
        addshowlist:false,
        code_url:'',
        code:'',
        initQCode: '',
        loading: false,
        address_id:'',
		disabled:false,
      }
    },
    mounted() {
      this.info = JSON.parse(localStorage.getItem('info'))
      this.mobile = localStorage.getItem('mobile')
      this.paramsdata = JSON.parse(localStorage.getItem('params'))
      console.log(this.paramsdata)
      this.Nocart  = this.$route.query.Nocart
      this.getDataadd()
      this.getProvince()
      this.getUserorder()
    },
    computed:{
			curAddress(){
				if(this.addressDatas.list.length>0){
					return this.addressDatas.list[this.addressDatas.index]
				}else{
					return undefined
				}
      },
      totalLength() {
				if (this.cart && this.cart.length > 0) {
					let total = 0;
					this.cart.map(item1 => {
						if (item1.list && item1.list.length > 0) {
							total += item1.list.length
						}
					})
					return total
				} else {
					return 0
				}
			}
    },
    filters: {
			formatDates(value) {
				  let date = new Date(parseInt(value) * 1000);
				  let y = date.getFullYear();
				  let m = date.getMonth() + 1;
				  m = m < 10 ? "0" + m : m;
				  let d = date.getDate();
				  d = d < 10 ? "0" + d : d;
				  let h = date.getHours();
				  h = h < 10 ? "0" + h : h;
				  let minute = date.getMinutes();
				  let second = date.getSeconds();
				  minute = minute < 10 ? "0" + minute : minute;
				  second = second < 10 ? "0" + second : second;
				  return y +"-" + m + "-" + d + " " + h + ":" + minute + ":"+second;
			},
				formatDate(value) {
				let date = new Date(parseInt(value) * 1000);
				let y = date.getFullYear();
				let m = date.getMonth() + 1;
				m = m < 10 ? "0" + m : m;
				let d = date.getDate();
				d = d < 10 ? "0" + d : d;
				let h = date.getHours();
				h = h < 10 ? "0" + h : h;
				let minute = date.getMinutes();
				let second = date.getSeconds();
				minute = minute < 10 ? "0" + minute : minute;
				second = second < 10 ? "0" + second : second;
				return y +"-" + m + "-" + d;
			}
    },
    methods: {
      // 生成二维码
      gitaddshowlist(){
          this.addshowlist = !this.addshowlist
      },
      gitdialog(){
        this.dialogVisible = false
        this.$router.push({ name: 'orderlist', query: {} })
      } ,
      // 选择地址
      gitchoseadd(id){
          this.addressDatas.index =  this.addressDatas.list.findIndex(r=>r.id==id)
          this.addshowlist = false
      },
      gitadderss(){
          this.dialogadders = true
      },
      todeatil(product_id) {
        this.$router.push({ name: 'shopdeatil', query: { product_id: product_id } })
      },
      radioChange(t) {
				if(t == 1){
					this.tapIndex = 1
				}else{
					this.tapIndex = 2
				}
			},
      // 获取用户收货地址
      getDataadd(options) {
        this.$http.post('/api/admin/shopweb/address/lists', { }).then(res => {
         this.addressDatas.loading = true;
					this.addressDatas.fail = false;
					if(res.code == 1){
						this.addressDatas.loading = false;
						if(res.data.length>0){
              this.addressDatas.list = res.data;
              if(res.data.findIndex(r=>r.is_default==1) != -1){
                this.addressDatas.index = res.data.findIndex(r=>r.is_default==1)
              }else{
                this.addressDatas.index = 0
              }
							// if(options.id){
							// 	this.addressDatas.index = res.data.findIndex(r=>r.id==options.id)
							// }else{
							
              // }
						}
					}else{
             this.$message({
                message: res.message,
                type: 'warning'
              })
						this.addressDatas.fail = true;
					}
        })
      },
      // 省份选择
        select1(){
            this.cityObj={}
            this.districtObj={}
            this.getCityList()
        },
        // 城市选择
        select2(){
            this.districtObj={}
            if(!this.provinceObj){
                this.$message.warning('请先选择省份')
                return
            }
            this.getAreaList()
        },
        // 县区选择
        select3(){
            if(!this.cityObj){
                this.$message.warning('请先选择城市')
                return
            }
        },
        // 获取省份
        getProvince(){
            this.$http.post('/api/admin/base/Region/getProvinceList').then(res=>{
                console.log(res,'省份');
                if(res.code==1){
                    this.province = res.data?res.data:[]
                }
            })
        },
        // 获取城市
        getCityList(city,area){
            this.$http.post('/api/admin/base/Region/getCityList',{province_id:this.provinceObj.cityid}).then(res=>{
                console.log(res,'城市列表');
                if(res.code==1){
                    this.city = res.data?res.data:[]
                    if(city){
                       this.cityObj =  this.city.find(val => val.city_name == city)
                       setTimeout(() =>{
                         this.getAreaList(area)
                       },150); 
                    }
                    
                }
            })
        },
        // 获取县区
        getAreaList(area){
            this.$http.post('/api/admin/base/Region/getDistrictList',{city_id:this.cityObj.cityid}).then(res=>{
                console.log(res,'县区列表');
                if(res.code==1){
                    this.district = res.data?res.data:[]
                    if(area){
                       this.districtObj = this.district.find(val => val.city_name == area)
                       setTimeout(() =>{
                          this.dialogadders = true
                          this.loading = false
                        },150);
                    }
                }
            })
        },
      isPhone(t) {
		        return /^1[3|4|5|6|7|8|9]\d{9}$/.test(t);
		 },  
         // 新增地址
      getadd() {
        console.log(this.provinceObj,this.cityObj,this.areaObj)
        if(!this.form.name){
          this.$message.warning('请填写收货人名称') 
          return
        }
        if(!this.form.mobile){
          this.$message.warning('请填写收货人号码') 
          return
        }
        if(!this.isPhone(this.form.mobile)){
          this.$message.warning('号码格式不对') 
          return
        }
        if(!this.districtObj){
          this.$message.warning('请选择区域') 
          return
        }
        if(!this.form.address){
          this.$message.warning('请填写详细地址') 
          return
        }
        this.$http.post('/api/admin/shopweb/address/add', { 
           name: this.form.name,
           mobile: this.form.mobile,
           address: this.form.address,
           province: this.provinceObj.city_name,
           city:this.cityObj.city_name,
           area:this.districtObj.city_name,			
           is_default: this.form.is_default	
        }).then(res => {
          if(res.code == 1){
              this.$message.success('添加地址成功！')
              this.getDataadd() 
              this.dialogadders = false
          }else{
            this.$message.warning(res.msg)
            this.dialogadders = false
          }
         
         
        })
      },
        // 编辑地址
      getedit() {
        console.log(this.provinceObj,this.cityObj,this.areaObj)
        if(!this.form.name){
          this.$message.warning('请填写收货人名称') 
          return
        }
        if(!this.form.mobile){
          this.$message.warning('请填写收货人号码') 
          return
        }
        if(!this.isPhone(this.form.mobile)){
          this.$message.warning('号码格式不对') 
          return
        }
        if(!this.districtObj){
          this.$message.warning('请选择区域') 
          return
        }
        if(!this.form.address){
          this.$message.warning('请填写详细地址') 
          return
        }
        this.$http.post('/api/admin/shopweb/address/edit', { 
           name: this.form.name,
           mobile: this.form.mobile,
           address: this.form.address,
           province: this.provinceObj.city_name,
           city:this.cityObj.city_name,
           area:this.districtObj.city_name,			
           is_default: this.form.is_default,
           address_id:this.address_id
        }).then(res => {
          if(res.code == 1){
              this.$message.success('编辑地址成功！')
              this.getDataadd()
              this.address_id = ''  
              this.dialogadders = false
          }else{
            this.$message.warning(res.msg)
            this.dialogadders = false
          } 
        })
      },
      editAddress(item){
        this.loading = true
        this.addtit='编辑收货地址'
        this.address_id = item.id
        this.form.name = item.name
        this.form.mobile = item.mobile
        this.form.address = item.address
        this.form.is_default	= item.is_default
        this.provinceObj = this.province.find(val => val.city_name == item.province)
        this.getCityList(item.city,item.area)
      },
      
      // 确认订单
     getUserorder() {
        let origin_type = this.paramsdata.origin_type
				let cart_ids = this.paramsdata.cart_ids
				let goods = this.paramsdata.goods
				let user_coupon_id = this.user_coupon_id
        this.$http.post('/api/admin/shopweb/order/confirm', {origin_type:origin_type,cart_ids:cart_ids,goods:goods,user_coupon_id:user_coupon_id}).then(res => {
          if (res.code == 1) {
            this.infos = res.data
						this.skuList = res.data.order_stores	
						this.countPrice()       // 计算价格
          }
        })
      },
      // 添加商品
			addCart(store_id, item) {
				// if(this.origin_type == 1){
					let cart = this.skuList
					let shop = cart.find(val => val.store_id == store_id)
					let goods = shop.goods.find(val => val.id == item.id)
					goods.pay_num++
					this.countPrice()       // 计算价格
					if(this.Nocart != 1){
            this.$http.post('/api/admin/shopweb/cart/setnum', { 
              id:item.id,
							num:goods.pay_num,
							action:'inc',
            }).then(res => {
            
            })
						this.getUserorder()
					}else{
						this.paramsdata.goods.num = goods.pay_num
						this.getUserorder()
					}
					
				// }else{
				// 	let cart = this.skuList
				// 	let shop = cart.find(val => val.store_id == store_id)
				// 	let goods = shop.goods
				// 	goods.pay_num++
				// 	this.countPrice()       // 计算价格
				// 	if(this.Nocart != 1){
				// 		service_mall.goods_numSave({
				// 			id:item.id,
				// 			num:goods.pay_num
				// 		})
				// 		this.getUserorder(this.local_order_list)
				// 	}else{
				// 		this.local_order_list.goods.num = goods.pay_num
				// 		this.getUserorder(this.local_order_list)
				// 	}
					
				// }
				
			},
			
			// 删减商品
			minusCart(store_id, item) {
				// if(this.origin_type == 1){
					let cart = this.skuList
					let shop = cart.find(val => val.store_id == store_id)
					let goods = shop.goods.find(val => val.product_id == item.product_id)
					if (goods.pay_num > 1) {
						goods.pay_num--
						this.countPrice()       // 计算价格
						if(this.Nocart != 1){
              this.$http.post('/api/admin/shopweb/cart/setnum', { 
                  id:item.id,
                  num:goods.pay_num,
                  action:'dec',
              }).then(res => {
              
              })
						   this.getUserorder()
						}else{
							this.paramsdata.goods.num = goods.pay_num
							this.getUserorder()
						}
					}
				// }else{
				// 	let cart = this.skuList
				// 	let shop = cart.find(val => val.store_id == store_id)
				// 	let goods = shop.goods
				// 	if (goods.pay_num > 1) {
				// 		goods.pay_num--
				// 		this.countPrice()       // 计算价格
				// 		if(this.Nocart != 1){
				// 			service_mall.goods_numSave({
				// 				id:item.id,
				// 				num:goods.pay_num
				// 			})
				// 		   this.getUserorder(this.local_order_list)
				// 		}else{
				// 			this.local_order_list.goods.num = goods.pay_num
				// 			this.getUserorder(this.local_order_list)
				// 		}
				// 	}
				// }
				
			},
      // 计算价格
			countPrice() {
			  // if(this.origin_type == 1){
				 let cost_price = 0
				 this.skuList.forEach(val => {
				 	val.goods.forEach(v => {
				 		cost_price = this.accAdd(cost_price, this.accMul(v.pay_num, v.cost_price))
				 	})
				 	
				 })
				 this.totalPrice = cost_price 
			  // }else{
				 //  let price = 0
				 //  this.skuList.forEach(val => {
				 //  		price = this.$utils.accAdd(price, this.$utils.accMul(val.goods.pay_num, val.goods.price))
				 //  })
				 //  this.totalPrice = price 
			  // }	
				
			},
      // js加法
	accAdd(arg1, arg2) {
		let r1, r2, m
		try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
		try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
		m = Math.pow(10, Math.max(r1, r2))
		return (this.accMul(arg1, m) + this.accMul(arg2, m)) / m;   
	},

	// js减法
	accSub(arg1, arg2) {
		let r1, r2, m
		try { r1 = arg1.toString().split(".")[1].length } catch (e) { r1 = 0 }
		try { r2 = arg2.toString().split(".")[1].length } catch (e) { r2 = 0 }
		m = Math.pow(10, Math.max(r1, r2));
		return (this.accMul(arg1, m) - this.accMul(arg2, m)) / m;  
	},

	// js乘法
	accMul(arg1, arg2) {
		let m = 0, s1 = arg1.toString(), s2 = arg2.toString()
		try { m += s1.split(".")[1].length } catch (e) { }
		try { m += s2.split(".")[1].length } catch (e) { }
		return Number(s1.replace(".", "")) * Number(s2.replace(".", "")) / Math.pow(10, m)
	},

	// js除法
	accDiv(arg1, arg2) {    
		let t1 = 0, t2 = 0, r1, r2 
		try { t1 = arg1.toString().split(".")[1].length } catch (e) { }
		try { t2 = arg2.toString().split(".")[1].length } catch (e) { }   
		r1 = Number(arg1.toString().replace(".", ""))    
		r2 = Number(arg2.toString().replace(".", ""))    
		return (r1 / r2) * Math.pow(10, t2 - t1)  
	},
    //  提交订单
    submitEvent(){
				if(!this.curAddress){
					uni.showToast({
						title: '请选择收货地址!',
						icon:'none',
						duration: 2000
					});
					return
				}
				if(this.disabled==true){
					return
				}else{
					this.disabled=true;//暂时禁用提交按钮
				}
				let origin_type = this.paramsdata.origin_type
				let cart_ids = this.paramsdata.cart_ids
				let ary = {}
				this.skuList.forEach(val => {
					val.goods.forEach(v => {
						ary = {
							sku_id: v.sku_id,
							pack_id: v.pack_id,
							num: v.pay_num
						}
					})
					
				})
      this.$http.post('/api/admin/shopweb/order/submit', { 
              origin_type:origin_type,
              cart_ids:cart_ids,
              goods:ary,
              address_id:this.curAddress.id,
              user_coupon_id:this.user_coupon_id
            }).then(res => {
              if(res.code == 1){
                let data = res.data
                this.order_codes = res.data.order_codes
                this.getpayorder(res.data.order_codes)  
              }else{
                this.$message.warning(res.msg)
              }
            })
    },
    getpayorder(order_codes){
            this.$http.post('/api/admin/shopweb/order/pay', { 
              order_no:order_codes,
              type:'purchase_order',
              pay_type:this.tapIndex
            }).then(res => {
              if(res.code == 1){
				     this.disabled=false;
						   let data = res.data
					       if(this.tapIndex == 1){
                     this.dialogVisible = true
                     this.code_url = res.data
                 }else{
                    this.code = res.data.verificationCode
                    this.initQCode = res.data.verificationCode
                    this.dialogVisible = true
                } 
              }else{
                this.$message.warning(res.msg)
              }
            })
    },

    
    }
  }
</script>
<style lang="less" scoped>
  & /deep/ .content {
    padding: 0 !important;
  }
  @import "../css/index.less";
</style>
